﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using negocio.servicios;

namespace Swimmers
{
    public partial class GestionCompetenciaNadador : System.Web.UI.Page
    {
        CompetenciaService comSer = new CompetenciaService();
        
        protected void Page_Load(object sender, EventArgs e)
        {
            int idCom = (int) Session["id_competencia"];
            DataTable dt = comSer.ObtenerCompetenciasById(idCom);
            cargarGrilla();
        }

        protected void cmd_Guardar_Click(object sender, EventArgs e)
        {
            int hora = Int32.Parse(txtHoraInicio.Text);
            DateTime fecha = DateTime.Parse(txt_fecha.Text);
            comSer.GuardarCompetencia(hora,fecha,Int32.Parse(Session["id_competencia"].ToString()),Int32.Parse(Session["id_torneo"].ToString()));
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Se inserto con exito')", true);
        }

        private void cargarGrilla()
        {
            grdNadadoresInscriptos.DataSource = comSer.ObtenerNadadores();
            string[] keys = new string[1];
            keys[0] = "id_nadador";
            grdNadadoresInscriptos.DataKeyNames = keys;
            grdNadadoresInscriptos.DataBind();
        }

        protected void grdVentas_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grdNadadoresInscriptos.PageIndex = e.NewPageIndex;
            cargarGrilla();

        }

        protected void txtApellido_TextChanged(object sender, EventArgs e)
        {
            Session["id_nadador"] = comSer.ObtenerIdNadador(txtNombre.Text, txtApellido.Text).ToString();
            lblIdSocio.Text = Session["id_nadador"].ToString();
        }

        protected void cmd_Generar_Click(object sender, EventArgs e)
        {
            comSer.InscribirNadadorCompetencia(Int32.Parse(Session["id_nadador"].ToString()), Int32.Parse(Session["id_competencia"].ToString()), Int32.Parse(Session["id_torneo"].ToString()));
            cargarGrilla();

        }   


    }
}